#ifndef PUBLICS_H
#define PUBLICS_H

#include <sys/time.h>      //添加头文件
#include <stdio.h>
#include <time.h>
#include <chrono>
#include <iostream>
#include <vector>
#include <sstream>
#include <math.h>
#include <QCursor>
#include <QBitmap>

enum ControlIndex{
    TP_ZOOM = 0,
    TP_X_STEP,
    TP_Y_STEP,
    TP_CAM_CHANGED,
    TP_GRID,
    TP_CAMX,
    TP_CAMY,
    TP_CAMZ,
    TP_CAMS     // 缩放
};

namespace Weldroid {
    using namespace std;
//    int64_t getCurrentTime()      //直接调用这个函数就行了，返回值最好是int64_t，long long应该也可以
//    {
//      struct timeval tv;
//      gettimeofday(&tv,NULL);    //该函数在sys/time.h头文件中
//      return tv.tv_sec * 1000 + tv.tv_usec / 1000;
//    }

//    std::string  getTime(bool isDate)
//    {
//       // 基于当前系统的当前日期/时间
//       time_t now = time(0);
//       tm *ltm = localtime(&now);


//       if(isDate){
//           int year = 1900 + ltm->tm_year;
//           int mon  = 1 + ltm->tm_mon;
//           int day = ltm->tm_mday;
//           return std::to_string(year) + "_" + std::to_string(mon) + "_" +  std::to_string(day);
//       }else{
//           int clock_ = ltm->tm_hour;
//           int min = ltm->tm_min;
//           int sec = ltm->tm_sec;
//           return std::to_string(clock_) + "_" + std::to_string(min) + "_" +  std::to_string(sec);
//       }
//    }

    struct RobotPos
    {
       double x, y, z, a, b, c;
       double dh, dw, v, acc;
       bool weld;    /// 断焊功能开关 false 空走 true 焊接
       static RobotPos instance(string str = "");
       std::string toStr(char sep=',');
       double dis(RobotPos p);
    };


    // 旋转光标
    static const QCursor& rotateCursor()
    {
        static QCursor cursor;
        if (!cursor.bitmap()) {
            const int rotateCursorWidth = 16;
            const int rotateCursorHeight = 16;
            const int rotateCursorByteCount =
                    ((rotateCursorWidth + 7) / 8) * rotateCursorHeight;
            const int rotateCursorHotX = 6;
            const int rotateCursorHotY = 8;

            static unsigned char rotateCursorBitmap[rotateCursorByteCount] = {
                0xf0, 0xef, 0x18, 0xb8, 0x0c, 0x90, 0xe4, 0x83,
                0x34, 0x86, 0x1c, 0x83, 0x00, 0x81, 0x00, 0xff,
                0xff, 0x00, 0x81, 0x00, 0xc1, 0x38, 0x61, 0x2c,
                0xc1, 0x27, 0x09, 0x30, 0x1d, 0x18, 0xf7, 0x0f
            };

            static unsigned char rotateCursorMaskBitmap[rotateCursorByteCount] = {
                0xf0,0xef,0xf8,0xff,0xfc,0xff,0xfc,0xff,0x3c,0xfe,0x1c,0xff,0x00,0xff,0x00,
                0xff,0xff,0x00,0xff,0x00,0xff,0x38,0x7f,0x3c,0xff,0x3f,0xff,0x3f,0xff,0x1f,
                0xf7,0x0f
            };

            const QBitmap cursorBmp = QBitmap::fromData(
                        QSize(rotateCursorWidth, rotateCursorHeight),
                        rotateCursorBitmap);
            const QBitmap maskBmp = QBitmap::fromData(
                        QSize(rotateCursorWidth, rotateCursorHeight),
                        rotateCursorMaskBitmap);
            const QCursor tempCursor(
                        cursorBmp, maskBmp, rotateCursorHotX, rotateCursorHotY);
            cursor = std::move(tempCursor);
        }
        return cursor;
    }

}

typedef Weldroid::RobotPos Pos3dzx;

#endif // PUBLICS_H
